package com.csu.letaobackend.controllerM;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csu.letaobackend.bean.Shop;
import com.csu.letaobackend.commom.CommonResponse;
import com.csu.letaobackend.serviceM.ShopMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin
@RequestMapping("/admin/shop")
public class ShopMController {

      @Autowired
      ShopMService shopMService;

      @GetMapping("/shops/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<Shop>> getAllShops(@PathVariable int pageid, @PathVariable int pagesize) {
            return shopMService.getAllShops(pageid, pagesize);
      }

      @GetMapping("/shops/search/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<Shop>> searchShop(@PathVariable int pageid, @PathVariable int pagesize,
                                             String shopname, String sellername) {
            return shopMService.searchShop(pageid, pagesize, shopname, sellername);
      }

      @PutMapping("/shops/{shopid}")
      @ResponseBody
      CommonResponse updateAvailable(@PathVariable int shopid, int available) {
            return shopMService.updateAvailable(shopid, available);
      }

      @DeleteMapping("/shops/{shopid}")
      @ResponseBody
      CommonResponse deleteShop(@PathVariable int shopid) {
            return shopMService.deleteShop(shopid);
      }
}
